/**
 * 按钮权限显示控制
 * {"按钮ID":"权限1，权限2"}
 * **/
function buttonPermissions(btnRoles) {
    const requestData = {
        btnRoles: btnRoles
    }
    return new Promise((resolve, reject) => {
        const btnRolesMap = new Map(Object.entries(btnRoles));
        $.ajax({
            type: "POST",
            url: '/role/checkUserRole',
            data: JSON.stringify(requestData),
            dataType: 'json',
            contentType: 'application/json; charset=UTF-8',
            success: function (req) {
                if (req.code === '200') {
                    const data = req.data;
                    let roles = data?.btnRoles;
                    if (!roles) {
                        return null;
                    }
                    // 循环Map 判断是否显示
                    btnRolesMap.forEach((value, key) => {
                        let btn = document.getElementById(key);
                        let isShow = roles[key];
                        if (btn) {
                            isShow ? btn.style.display = '' : btn.style.display = 'none';
                        }
                    });
                    resolve(new Map(Object.entries(roles)));
                } else {
                    btnRolesMap.forEach((value, key) => {
                        btnRolesMap.set(key, false)
                    });
                    resolve(btnRolesMap)
                }
            },
            error: function (e) {
                layer.msg(e.msg);
                btnRolesMap.forEach((value, key) => {
                    btnRolesMap.set(key, false)
                });
                resolve(btnRolesMap)
            }
        })
    });

}